package org.jeecg.modules.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.common.utils.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.weixin.entity.JsonRootBean;

import java.util.Map;

@Slf4j
public class WxUtils {
    private static String grantType="client_credential";

    private static String appid="wx42ecd92353c89e9f";

    private static String secret="955609cb9cb5d3ee036caaed2f883277";

    public static Map<String,String> sendMessage2(String AccessToken, JsonRootBean jsonRootBean){
        JSONObject json = (JSONObject) JSON.parseObject(JSON.toJSONString(jsonRootBean));       //把JsonRootBean转成JSONObject对象
        String info = HttpUtils.sendPostJson(json, "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + AccessToken);
        Map<String,String> map = (Map) JSON.parse(info);
        System.out.println(map);
        return map;
    }

    public static  Map<String,Object> getTemplateList(String AccessToken){
        String info = HttpUtils.sendGet("https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=" + AccessToken);
        Map<String,Object> map = (Map) JSON.parse(info);
        System.out.println(map);
        return map;
    }

    public static Map<String,String> getAccessToken(){
        String s = HttpUtils.sendGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=" + grantType + "&appid=" + appid + "&secret=" + secret);
        Map<String,String> map = (Map) JSON.parse(s);
        System.out.println(map);
        return map;
    }

}
